package com.jiang.daily.Q732;

import java.util.Map;
import java.util.TreeMap;

/**
 * @author Jiang
 * @version 1.0
 * @date 2025/01/04 23:25
 */
class MyCalendarThree {
    TreeMap<Integer, Integer> map;

    public MyCalendarThree() {
        map = new TreeMap<>();
    }

    public int book(int startTime, int endTime) {
        int maxBook = 0;
        int res = 0;
        map.put(startTime, map.getOrDefault(startTime, 0) + 1);
        map.put(endTime, map.getOrDefault(endTime, 0) - 1);
        for (Map.Entry<Integer, Integer> entry: map.entrySet()) {
            maxBook += entry.getValue();
            res = Math.max(maxBook, res);
        }
        return res;
    }
}
